package top.zhongyy.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.zhongyy.mapper.BlogMapper;
import top.zhongyy.pojo.Blog;
import top.zhongyy.service.ArchiveService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Created by IntelliJ IDEA.
 * @DESC:归档博客实现类
 * @Author: Andy
 * @Date: 2021/3/28
 */

@Service
public class ArchiveBlog implements ArchiveService {
    
    @Autowired
    private BlogMapper blogMapper;
    
    @Override
    public Map<String, List<Blog>> getArchiveBlogs() {
        HashMap<String, List<Blog>> map = new HashMap<>();
        List<Long> years = blogMapper.getAllYear();
        for (Long year : years) {
            map.put(String.valueOf(year), blogMapper.getBlogsByYear(year));
        }
        return map;
    }
}
